package utils

import (
	"github.com/gorilla/websocket"
	"sync"
)

var (
	mu      sync.Mutex
	clients = make(map[string]*websocket.Conn) // 用户ID -> WebSocket 连接

)

// AddClient 添加用户websocket 连接
func AddClient(userID string, conn *websocket.Conn) {
	mu.Lock()
	clients[userID] = conn // 添加用户ID和WebSocket连接到映射中

	defer mu.Unlock()

}

// RemoveClient 移除用户websocket连接
func RemoveClient(userID string) {
	mu.Lock()
	delete(clients, userID)
	defer mu.Unlock()

}

// GetClient 获取用户websocket连接
func GetClient(userID string) *websocket.Conn {
	mu.Lock()

	defer mu.Unlock()

	return clients[userID]

}
